<!DOCTYPE html>
<html lang="zh-CN">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>类的基本知识</title>
</head>

<body>
  <script>
    class Person {
      // 构造器
      constructor(name, age) {
        this.name = name
        this.age = age
      }

      speak () {
        // 方法放在了构造函数的原型对象上，供实例使用
        console.log(`我叫 ${this.name}, 今年 ${this.age} 岁`)
      }
    }

    class Student extends Person {
      constructor(name, age) {
        super(name, age)
        this.school = 'atguigu'
      }
      
      speak () {
        console.log(`我叫 ${this.name}, 今年 ${this.age} 岁, 我正在学习React...`)
      }

      study () {
        console.log('学习React...')
      }
    }

    const p1 = new Person('Tom', 22)
    const p2 = new Person('Jack', 24)
    console.log(p1)
    console.log(p2)
    const s1 = new Student('Jet', 24)
    console.log(s1)
    s1.speak()
    s1.study()
  </script>
</body>

</html>